#!/usr/bin/env python
# -*- coding: UTF-8 -*-
'''
@Project ：HiflyVideoAPI_Test 
@File    ：TestCaseCozeCreateTaskhasHiflyid.py
@Author  ：beibei
@Date    ：7/30/25 4:11 PM 
'''

from datetime import datetime
from logging import info

import unittest

from business.voices.vo import BusinessRe
from common.assertCommon import AssertCommon
from common.caseOutput import class_case_decoration
from common.yamlLoader import YamlRead
from utils.utils_base import save_json_response, get_random_template_id, get_random_avatar_v2
from utils.utils_font import get_random_chinese_text



@class_case_decoration
class TestCaseCreateTaskhashilfyCoze(unittest.TestCase):

    ac = AssertCommon()
    env_config = YamlRead().env_config1()
    host = env_config['host']
    br = BusinessRe()
    authorization = env_config['Authorization_coze']


    def testCase01_coze_hiflyid_create_task(self):
        """使用 audio_url + voice_id，语音驱动合成-不会截断是3分钟"""
        info('【step】语音驱动合成')
        url = self.host + f'/api/v1/hifly/task/create'
        body = {
            "audio_url": "https://shortvideo-cdn-dev.lingverse.co/hf/local/37/audios/3min.wav",
            "title": "3min-audio_url&video_url",
            "video_url": "https://shortvideo-cdn-dev.lingverse.co/hf/local/124/videos/118.mp4",
            "hifly_id": "hFn4Dl0OxsAb+jm/ZvjepQ=="
        }
        res = self.br.post(url, self.authorization, body)
        info('【step】断言 code == 0')
        self.ac.code_assert(0, res.json()["code"])
        save_json_response(res.json(), "data/response/task/coze/nohiflyid/create_task_audio&video_v1.json")

    def testCase02_coze_hiflyid_create_template(self):
        """创建任务-模板类型-700个字全读完
        """
        url = self.host + f'/api/v1/hifly/video/create_by_template'
        template_id = get_random_template_id()
        body = {
            "title": "700字template_" + datetime.now().strftime("%Y%m%d_%H%M%S"),
            "avatar": get_random_avatar_v2(),
            "voice": "db65c1a8-b2aa-4e6e-8992-e6a61857e7cf",
            "text": get_random_chinese_text(700),
            "template": template_id,
            "template_name": "小镇姑娘",
            "template_role": "旅游大使",
            "template_title": "家乡的旅游计划家乡的旅游计划家乡的旅游计划家乡的旅游计划家乡的旅游计划",
            "hifly_id": "hFn4Dl0OxsAb+jm/ZvjepQ=="
        }
        res = self.br.post(url, self.authorization, body)

        info('【step】断言 code == 0')
        self.ac.code_assert(0, res.json()["code"])

        info('【step】断言返回结构字段和类型校验')
        expected = {
            "job_id": int,
            "message": str,
            "code": int,
            "request_id": str
        }
        self.ac.json_assert(expected, res.json())

        save_json_response(res.json(), "data/response/task/coze/nohiflyid/create_task_create_template_coze_nohiflyid.json")

    def testCase03_coze_hiflyid_create_tts(self):
        """创建任务-模板类型-700个字全读完
                """
        url = self.host + f'/api/v1/hifly/task/create'
        template_id = get_random_template_id()
        body = {
            "title": "700字自动化tts_" + datetime.now().strftime("%Y%m%d_%H%M%S"),
            "video_url": "https://shortvideo-cdn-dev.lingverse.co/hf/local/124/videos/044411cf-6928-44f9-8dcd-1db93693522c.mp4",
            "voice_type": 10,
            "voice_id": 594,
            "text": get_random_chinese_text(700),
            "hifly_id": "hFn4Dl0OxsAb+jm/ZvjepQ=="
        }
        res = self.br.post(url, self.authorization, body)

        info('【step】断言 code == 0')
        self.ac.code_assert(0, res.json()["code"])

        info('【step】断言返回结构字段和类型校验')
        expected = {
            "job_id": int,
            "message": str,
            "code": int,
            "request_id": str
        }
        self.ac.json_assert(expected, res.json())

        save_json_response(res.json(),
                           "data/response/task/coze/nohiflyid/create_task_create_tts_coze_nohiflyid.json")

    def testCase04_coze_hiflyid_create_podcast(self):
        """创建tts类型-应为10分钟
        podcast_url="播客地址"
        """
        url = self.host + f'/api/v1/hifly/video/create_by_podcast'
        body = {
            "podcast_url": "https://shortvideo-cdn.lingverse.co/s/podcast-long.html",
            "hifly_id": "hFn4Dl0OxsAb+jm/ZvjepQ=="
        }
        res = self.br.post(url, self.authorization, body)

        info('【step】断言 code == 0')
        self.ac.code_assert(0, res.json()["code"])

        info('【step】断言返回结构字段和类型校验')
        expected = {
                    "job_id": int,
                    "message": str,
                    "code": int,
                    "request_id": str
        }
        self.ac.json_assert(expected, res.json())

        save_json_response(res.json(), "data/response/task/coze/nohiflyid/create_task_create_podcast_coze_nohiflyid.json")

